// pages/album_music/album_music.js
var app = getApp()
Page({
  data:{
    play_hidden:false,
    pause_hidden:true,
    domain:null
  },
  onLoad:function(o){
    var album = wx.getStorageSync('album_info_s')
    this.setData({
      album:album,
      domain:app.globalData.domain,
      play_img:app.globalData.domain+'/Sites/Site34/Album/main/play.png',
      pause_img:app.globalData.domain+'/Sites/Site34/Album/main/pause.png'
    })
    this.Get_Music(1)
  //  var m = this.data.domain+'/Sites/Site34/Album_audio/20170412145707.mp3'
   // this.music_init(m)
  },


//获取表单数据 
  formSubmit(e){
   // console.log(e.detail.value.music)
    var album = wx.getStorageSync('album_info_s')
    album.Album_music=e.detail.value.music
    wx.setStorageSync('album_info_s',album)
   // console.log(album)
    wx.redirectTo({url:'../album_add/album_add'})
  },


//上下翻页
  Flip_Page(e){
    var flip = e.currentTarget.dataset.type
    var pnow = e.currentTarget.dataset.pnow
    if(flip == 'last'){
      if(this.data.music_info.Pnow > 1){
        var last = this.data.music_info.Pnow -1
      }else{
        last = 1
      }
      this.Get_Music(last)
    }else{
      if(this.data.music_info.Pnow < this.data.music_info.PageCount){
        var last = this.data.music_info.Pnow + 1
      }else{
        var last = this.data.music_info.PageCount
      }
      this.Get_Music(last)
    }
  },



//获取背景音乐
  Get_Music(pnow){
    var t = this
    wx.request({
      url:app.globalData.urls,
      data:{
        'GetTypes':'Get_Music',
        'pnow':pnow
      },
      success:function(res){
       // console.log(res.data)
        t.setData({
          music_info:res.data
        })
      }
    })
  },


  music_play(e){
    var music_src = e.currentTarget.dataset.src
    var music_idx = e.currentTarget.dataset.idx


    if(this.data.music_stat){
      this.setData({
        current_music:music_idx,
        music_stat:null
      })
     // console.log(this.data.music_stat)
    //  console.log(wx.getStorageSync('music_stat'))
      this.audioPause()       //停止音乐
    }else{
      this.setData({
        current_music:music_idx,
        music_stat:1
      })
    //  console.log(this.data.music_stat)
    //  console.log(wx.getStorageSync('music_stat'))
      this.music_init(this.data.domain+music_src)   //播放音乐
    }

  },


  music_init(music_src){
    this.audioCtx = wx.createAudioContext('myAudio')
    this.audioCtx.setSrc(music_src)
    this.audioCtx.play()
  },


  audioPlay: function () {
    this.audioCtx.play()
  },
  audioPause: function () {
    this.audioCtx.pause()
  },
  audio14: function () {
    this.audioCtx.seek(14)
  },
  audioStart: function () {
    this.audioCtx.seek(0)
  }
 

})